import { useState } from 'react';
import { createStore } from 'redux';

const defState: IRootState = {
  ToastData: {
    isShow: false,
    message: 'test',
    type: 'success',
    title: '',
  },
};
// eslint-disable-next-line react-hooks/rules-of-hooks
// const [title, setTitle] = useState('');

const reducer = (state = defState, action: IAction) => {
  state = JSON.parse(JSON.stringify(state));
  switch (action.type) {
    case 'Toast_show':
      let payload = action.payload as IToastPayload;
      state.ToastData.type = payload.type;
      state.ToastData.message = payload.message;
      state.ToastData.isShow = true;
      // state.ToastData.title=value

      break;
    case 'Toast_hide':
      state.ToastData.isShow = false;
      break;
  }
  return state;
};

const store = createStore(reducer);

export default store;
